/**
 * Copyright © 2011 looty - Textoo
 * @link http://www.textoo.org
 * @link http://code.google.com/p/textoo/
 * @author lab9 - Bertrand Larrieu
 * @mail lab9.fr@gmail.com
 * @version 2.0
 */

package org.looty.core.textoo.render.glyph 
{
	import flash.display.*;
	import flash.geom.*;
	import flash.utils.*;
	
	public class GlyphBitmapData
	{
		private var _colors		:Dictionary;	
		private var _bitmapData	:BitmapData;
		private var _offset		:Point;
		
		static private const POINT:Point = new Point();
		
		public function GlyphBitmapData(bitmapData:BitmapData, colorRect:Rectangle, bounds:Rectangle, color:uint) 
		{			
			_offset = new Point(colorRect.x - bounds.x, colorRect.y - bounds.y);
			
			_bitmapData = new BitmapData(colorRect.width, colorRect.height, true, 0);
			_bitmapData.copyPixels(bitmapData, colorRect, POINT);
			
			_colors = new Dictionary();
			_colors[color] = _bitmapData;			
		}
		
		public function getColor(value:Number):BitmapData
		{
			if (_colors[value] == null)
			{
				var bmd:BitmapData = _bitmapData.clone();
				var transform:ColorTransform = new ColorTransform();
				transform.color = value;
				bmd.colorTransform(bmd.rect, transform);
				_colors[value] = bmd;
			}		
			
			return _colors[value];
		}
		
		public function get offset():Point 
		{
			return _offset;
		}
		
	}
	
}